package com.xrit.sunnyday.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.xrit.sunnyday.pojo.CheckGroup;
import com.xrit.sunnyday.service.CheckGroupService;
import com.xrit.sunnyday.common.MessageConstant;
import com.xrit.sunnyday.common.PageResult;
import com.xrit.sunnyday.common.QueryPageBean;
import com.xrit.sunnyday.common.Result;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/CheckGroup")
public class CheckGroupController {
    //远程连接
    @Reference
    private CheckGroupService checkGroupService;
    /*
    查询所有
     */
    @PostMapping("/findAll.do")
    public Result findAll(){
        List<CheckGroup> groupList = checkGroupService.findAll();
        return new Result(true, MessageConstant.QUERY_CHECKGROUP_SUCCESS,groupList);
    }
    /*
    查询所有并分页
     */
    @RequestMapping("/findPageAll.do")
    public Result findPageAll(@RequestBody QueryPageBean queryPageBean){
        PageResult pageAll = checkGroupService.findPageAll(queryPageBean);
        return new Result(true,MessageConstant.QUERY_CHECKGROUP_SUCCESS,pageAll);
    }
    /*
    添加检查组
     */
    @PostMapping("/add.do")
    public Result add(Integer[] checkitemIds,@RequestBody CheckGroup checkGroup){
        checkGroupService.add(checkGroup,checkitemIds);
        return new Result(true,MessageConstant.ADD_CHECKGROUP_SUCCESS);
    }
    /*
    根据id查询检查组
     */
    @GetMapping("/findById.do")
    public Result findById(Integer id){
        CheckGroup checkGroup = checkGroupService.findById(id);
        return new Result(true,MessageConstant.QUERY_CHECKGROUP_SUCCESS,checkGroup);
    }
    /*
    根据id查询检查组检查项中间表
     */
    @GetMapping("/findCheckGroupItem.do")
    public Result findCheckGroupItem(Integer id){
        List<Integer> i = checkGroupService.findCheckGroupItem(id);
        return new Result(true,MessageConstant.QUERY_CHECKITEM_SUCCESS,i);
    }
    /*
    根据修改
     */
    @RequestMapping("/update")
    public Result update(@RequestBody CheckGroup checkGroup ,Integer[] ids){
        checkGroupService.update(ids,checkGroup);
        return new Result(true,MessageConstant.EDIT_CHECKGROUP_SUCCESS);
    }
    /*
    根据id删除
     */
    @RequestMapping("/deleteById.do")
    public Result deleteById(Integer id){
        checkGroupService.deleteById(id);
        return new Result(true,MessageConstant.DELETE_CHECKGROUP_SUCCESS);
    }
}
